package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Quality;
import com.hengxinguotong.zhihuichengjian.bean.SecurityAccident;
import com.hengxinguotong.zhihuichengjian.treeview.*;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class QualityAccidentListAdapter extends RecyclerAdapter<SecurityAccident, QualityAccidentListAdapter.QualityAccidentViewHolder> {

    public QualityAccidentListAdapter(Context context, List<SecurityAccident> dataList) {
        super(context, dataList);
    }

    @Override
    public QualityAccidentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_quality, null);
        return new QualityAccidentViewHolder(view);
    }

    @Override
    public void onBindViewHolder(QualityAccidentViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class QualityAccidentViewHolder extends RecyclerAdapter.BaseViewHolder<SecurityAccident> {
        @BindView(R.id.state_iv)
        ImageView stateIv;
        @BindView(R.id.state_tv)
        HXTextView stateTv;
        @BindView(R.id.content)
        HXTextView content;
        @BindView(R.id.structure_tv)
        HXTextView structureTv;
        @BindView(R.id.person_tv)
        HXTextView personTv;
        @BindView(R.id.company_tv)
        HXTextView companyTv;
        @BindView(R.id.data_tv)
        HXTextView dataTv;

        public QualityAccidentViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
        
        @Override
        public void bindData(final int position) {
            SecurityAccident qualityAccident = dataList.get(position);
            dataTv.setText(qualityAccident.getBusinessDate());
//        dataTv.setText(qualityAccident.getCreateTime());
            content.setText(qualityAccident.getItems());
            personTv.setText(qualityAccident.getContactName());
            if(qualityAccident.getProjectCompanyName() == null){
                companyTv.setText("无");
            }else{
                if( qualityAccident.getProjectCompanyName().length() > 12){
                    companyTv.setText(qualityAccident.getProjectCompanyName().substring(0, 11) + "...");
                }else{
                    companyTv.setText(qualityAccident.getProjectCompanyName());
                }
            }

            if(qualityAccident.getProjectStructureName() == null || Utils.isEmpty(qualityAccident.getProjectStructureName())){
                structureTv.setText("无工程结构");
            }else{
                structureTv.setText(qualityAccident.getProjectStructureName());
            }

            switch (qualityAccident.getStatus()) {
                case 1:
                    stateIv.setImageResource(R.mipmap.small_commonly);
                    stateTv.setText("一般");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_71e5a2));
                    break;
                case 2:
                    stateIv.setImageResource(R.mipmap.small_serious);
                    stateTv.setText("较大");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_ffc065));
                    break;
                case 3:
                    stateIv.setImageResource(R.mipmap.small_major);
                    stateTv.setText("重大");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_f1636a));
                    break;
                case 4:
                    stateIv.setImageResource(R.mipmap.small_bigness);
                    stateTv.setText("特别重大");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_c9222a));
                    break;

            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickListener.onClick(position);
                }
            });
        }
    }
}
